﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using OgilvyOne.BLL;
using OgilvyOne.Model;

using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Model;
using System.Collections.Generic;
using ECCIT;
using System.IO;
public partial class admin_UKNOW_news_news_phone_image_list : AdminBasePage
{
    private const string VIEWSTATE_NEWSID = "newID";
    //
    private const string VIEWSTATE_COLUMN_ID = "columnid";
    private const string VIEWSTATE_LAYER_ID = "layerid";
    private const string VIEWSTATE_LANG_ID = "langID";
    private const string VIEWSTATE_IMG_ID = "PhoneImgID";
    //
    private const string VIEWSTATE_PAGE_NO = "pageNum";
    //

    public int isaudit = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.headers.Text = "新闻手机图片管理";
            //
            ViewState[VIEWSTATE_COLUMN_ID] = int.Parse(Request.Params[VIEWSTATE_COLUMN_ID]);
            ViewState[VIEWSTATE_LAYER_ID] = Request.Params[VIEWSTATE_LAYER_ID];
            //
            string newsid = Request.Params[VIEWSTATE_NEWSID];
            ViewState[VIEWSTATE_NEWSID] = newsid;
            //
            this.headers.Text = new ColumnBll().LayeridColumnConNaiv(Request.Params[""]);
            ViewState[VIEWSTATE_PAGE_NO] = "1";
            //
            Grid_viewBild();
        }
        else
        {
            if (string.IsNullOrEmpty(ViewState[VIEWSTATE_PAGE_NO].ToString())) return;
            string sPageNum = Request.Params[VIEWSTATE_PAGE_NO];
            if (ViewState[VIEWSTATE_PAGE_NO].ToString() != sPageNum)
            {
                ViewState[VIEWSTATE_PAGE_NO] = sPageNum;
                Grid_viewBild();
            }
        }
    }
    private int? GetNewsIDFromViewState()
    {
        object obj = GetViewStateVariables(VIEWSTATE_NEWSID);
        if (obj == null)
            return null;

        int newsID;
        bool b = int.TryParse(obj.ToString(), out newsID);
        if (b) return newsID;
        return null;
    }

    private void Grid_viewBild()
    {
        int? newsID = GetNewsIDFromViewState();

        IList<EventsImageModel> datalist = new NewsPhoneImageBLL(LangID).GetAllNewsPhoneImageModels(newsID);
        GridView1.DataSource = datalist;
        GridView1.PageSize = 10;
        //

        GridView1.PageIndex = int.Parse(ViewState[VIEWSTATE_PAGE_NO].ToString()) - 1;
        //
        GridView1.DataBind();
        this.pagehtml.Text = getPageHtml(GridView1.PageCount, GridView1.PageIndex + 1, datalist.Count);
    }

    protected void Add_click(object sender, EventArgs e)
    {
        string url = string.Format("new_Phone_Img_add.aspx?{0}={1}&{2}={3}&{4}={5}&{6}={7}", VIEWSTATE_COLUMN_ID, ViewState[VIEWSTATE_COLUMN_ID], VIEWSTATE_NEWSID, ViewState[VIEWSTATE_NEWSID], VIEWSTATE_LAYER_ID, ViewState[VIEWSTATE_LAYER_ID], VIEWSTATE_LANG_ID, this.LangID);
        Response.Redirect(url);
    }

    protected void Mod_click(object sender, EventArgs e)
    {
        string url = string.Format("new_Phone_Img_add.aspx?{0}={1}&{2}={3}&{4}={5}&{6}={7}&{8}={9}",
            VIEWSTATE_COLUMN_ID, ViewState[VIEWSTATE_COLUMN_ID],
            VIEWSTATE_NEWSID, ViewState[VIEWSTATE_NEWSID],
            VIEWSTATE_LAYER_ID, ViewState[VIEWSTATE_LAYER_ID],
            VIEWSTATE_LANG_ID, this.LangID,
            VIEWSTATE_IMG_ID, int.Parse(((LinkButton)sender).CommandArgument));

        Response.Redirect(url);
    }

    //删除某个图片的数据
    protected void Del_click(object sender, EventArgs e)
    {

        int ids = int.Parse(((LinkButton)sender).CommandArgument);
        //根据图片id 获取该图片对象
        EventsImageModel model = new NewsPhoneImageBLL(this.LangID).selImage(ids);
        string filename = model.Path;
        string path = Server.MapPath("~/uploadfiles/image/");


        ResultInfo res = new NewsPhoneImageBLL(LangID).delImage(ids);//删除数据库上的图片
        if (res.Result)
        {
            Response.Write("<script>alert('" + res.Message + "')</script>");
        }
        else
        {
            Response.Write(res.Message);
        }

        Grid_viewBild();
    }

    //修个单个图片的发布状态
    protected void Set_click(object sender, EventArgs e)
    {
        //修改单个图片的发布状态
        int mid = int.Parse(((LinkButton)sender).CommandArgument);
        new NewsPhoneImageBLL(LangID).modPubOne(mid);
        Grid_viewBild();
    }
    protected void Return_click(object sender, EventArgs e)
    {
        Response.Redirect("News.aspx?columnid=" + ViewState[VIEWSTATE_COLUMN_ID] + "&layerid=" + ViewState[VIEWSTATE_LAYER_ID] + "&langID=" + LangID);
    }
}